跳到主要内容

裁剪 ROI 端点(仅分类)

概览

cropped_roi 端点提供对在设备上运行的 Haystack 中,从 classification results 生成的 裁剪的 Regions of Interest (ROIs) 的访问。

重要提示: 该端点仅适用于 classification-type results。 通过此端点进行 ROI 裁剪不支持 Segmentation(分割)类型。

基本 URL 格式为:

http://{device-ip}/edge/haystack/cropped_roi/{classification_result_id}

工作原理

当相机完成一次 classification capture 时,Node-RED 流会通过将设备 IP 与 classification result ID 配对,动态构造裁剪 ROI 图像的 URL:

const imageUrl = `http://${baseUrl}/edge/haystack/cropped_roi/${result.id}`;

每个 URL 提供与单个 classification ROI 相对应的裁剪图像,通常表示一次单独的质检。


Node-RED 流程摘要

ROI_Crop 流程执行以下操作:

  1. 提取设备 IP

    • 解析 image_url 字段以找到设备 IP(例如 192.168.0.101
    • 将其全局存储以便重复使用
  2. 查询最新捕获数据

    • 向设备的 PostgREST API 发送 GET 请求:

      http://{device-ip}/postgrest/captures?select=...
      &order=id.desc&limit=1
    • 检索最近的捕获以及所有 classification_result 条目

  3. 仅筛选分类结果

    • 跳过分割或对齐结果

    • 迭代每个 classification result:

      classificationResults.forEach(result => {
      const roiName = result.roi_result?.inspection_region?.name || `ROI_${result.id}`;
      const imageUrl = `http://${baseUrl}/edge/haystack/cropped_roi/${result.id}`;
      imageMap[roiName] = imageUrl;
      });
  4. 输出裁剪 ROI 的 URL

    • 将所有 ROI 图像链接保存到全局变量 imageMap
    • 返回最新裁剪 ROI 图像 URL 列表

image1.png

image2.png

示例用法

获取裁剪 ROI 图像

curl http://192.168.0.101/edge/haystack/cropped_roi/42 -o roi_42.jpg

在网页界面中的使用

<img src="http://192.168.0.101/edge/haystack/cropped_roi/42" alt="Cropped ROI 42">

输出示例

{
"ROI_1": "http://192.168.0.101/edge/haystack/cropped_roi/1",
"ROI_2": "http://192.168.0.101/edge/haystack/cropped_roi/2"
}

参数

参数类型描述
device-ipstring摄像头的 IP 地址(例如 192.168.0.101

集成流程

  1. 通过 /postgrest/captures 获取最新捕获元数据。
  2. 确定可用的 classification_result ID。
  3. 为每个结果构造裁剪 ROI 的 URL。
  4. 显示或下载这些图像以用于分析、训练数据或 QA 质检。

下载 Node-RED 流

  • ROI Crop Flow (JSON) - 用于提取裁剪 ROI 图像的完整 Node-RED 流
    • 将此流直接导入 Node-RED 以访问裁剪的 classification ROIs
    • 适用于 OV20i 和 OV80i 系统